package com.kbt.activity;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.*;
import com.kbt.base.BaseApplication;
import com.kbt.util.tool.BtnSetting;
import com.kbt.util.utils.SharePreferenceUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * @Title: KBT_ANDRIOD
 * @Copyright: KJ Co., Ltd. Copyright 2015-2020,  All rights reserved
 * @Description: ${todo}<请描述此文件是做什么的>
 * @author: zhgk
 * @data: 2015/8/19 11:05
 * @version: V1.0
 */
public class SettingActivity extends Activity {
    private SharePreferenceUtils share;
    private ImageLoader imageLoader;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // setContentView(R.layout.seeting);
        this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.seeting);
        this.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_return_btn);

        //设置返回按钮事件,关闭当前Activity，返回数据
        ImageView returnImg = (ImageView) findViewById(R.id.return_btn);
        returnImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //不创建地址
                setResult(RESULT_CANCELED, null);
                BaseApplication.getInstance().removeActivity(SettingActivity.this);
                finish();
            }
        });
         imageLoader = ImageLoader.getInstance();
        TextView appTitleView = (TextView) findViewById(R.id.center_title);
        appTitleView.setText("设置");
        share = new SharePreferenceUtils(SettingActivity.this);
    }

    @Override
    protected void onStart() {
        super.onStart();

        BaseApplication.getInstance().addActivity(SettingActivity.this);
        //消息通知
        ToggleButton switchBtn = (ToggleButton) findViewById(R.id.switch_msg_btn);
        switchBtn.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                                         boolean isChecked) {
                // TODO Auto-generated method stub
                if (isChecked) {
                    //打开消息通知功能
                } else {
                    //关闭消息通知功能
                }
            }
        });

        TextView cleanCacheText = (TextView) findViewById(R.id.cleanCacheBtn);
        Button cleanCacheArrow = (Button) findViewById(R.id.cleanCacheArrow);
        cleanCacheText.setOnClickListener(new CleanCacheVersionClickListener());
        cleanCacheArrow.setOnClickListener(new CleanCacheVersionClickListener());

        TextView newVerText = (TextView) findViewById(R.id.checkNewVerBtn);
        Button newVerArrow = (Button) findViewById(R.id.checkNewVerArrow);
        newVerText.setOnClickListener(new CheckNewVersionClickListener());
        newVerArrow.setOnClickListener(new CheckNewVersionClickListener());

        TextView aboutText = (TextView) findViewById(R.id.aboutKBTBtn);
        Button aboutArrow = (Button) findViewById(R.id.aboutKBTArrow);
        aboutText.setOnClickListener(new AboutKbtClickListener());
        aboutArrow.setOnClickListener(new AboutKbtClickListener());

        Button exitBtn = (Button) findViewById(R.id.exitLogin);
//        BtnSetting.setBtnBackground(exitBtn, 2, Color.RED, Color.RED, 5);
        exitBtn.setTextColor(Color.WHITE);
        exitBtn.setOnClickListener(new LoginOutClickListener());

    }

    /****
     * 清除缓存
     */
    private class CleanCacheVersionClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            //退出账号登录
            //关于固本堂
            imageLoader.clearMemoryCache();
            Toast.makeText(getApplication(), "清除缓存成功", Toast.LENGTH_SHORT).show();
        }
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    /****
     * 检测新版本
     */
    private class CheckNewVersionClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            //退出账号登录
            //关于固本堂
            Toast.makeText(getApplication(), "已是最新版本", Toast.LENGTH_SHORT).show();
        }
    }


    /****
     * 关于固本堂
     */
    private class AboutKbtClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            //退出账号登录
            //关于固本堂
            Toast.makeText(getApplication(), "敬请期待!", Toast.LENGTH_SHORT).show();
        }
    }


    /****
     * 退出账号事件
     */
    private class LoginOutClickListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            //退出账号登录
            //使用全局变量，保存账号状态
            BaseApplication.getInstance().shopType=0;
            share.put("user_mobile", "");
            share.put("password","");
            share.put("user_key","");
            BaseApplication.getInstance().removeActivity(SettingActivity.this);
            finish();
        }
    }
}
